$(function() {
    $("[data-toggle='popover']").popover();

    var vcodeStatus = getQueryVariable("status");
	if(vcodeStatus === "vcodeerror") {
		$('#vcode_img').popover('show');
		$('#vcode').click( function() {
			$('#vcode_img').popover('hide');
		})
	}else if(vcodeStatus === "signinerror"){
		$('#signin').popover('show');
	    $('#username').click( function() {
			$('#signin').popover('hide');
		})
		$('#password').click( function() {
			$('#signin').popover('hide');
		})
	}
})

function changeImg() {
    var vcode = document.getElementById("vcode_img");
    var timestamp = (new Date()).valueOf();
    vcode.src = "./VCode?timestamp=" + timestamp;
}
  
function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
    }
    return(false);
}